# from selenium import webdriver
# from selenium.webdriver.common.action_chains import ActionChains
from appium import webdriver
import time,os


desired_caps = {}       # 定义webdriver的兼容性设置字典对象用于设置核心参数
desired_caps['platformName'] = 'Android'    # 指定测试Android平台
desired_caps['platformVersion'] = '5.1'   # 指定移动端的版本号
desired_caps['deviceName'] = 'Appium'       # 指定设备名称
desired_caps['appPackage'] = 'com.bluephone'  # 指定要启动的包
desired_caps['appActivity'] = 'com.bluecart.activity.SplashActivity' # 指定启动的主类程序
desired_caps['noReset'] = True
desired_caps['unicodeKeyboard'] = True         #可以输入中文
desired_caps['udid'] = 'MT66-2WA-9D06127'    # 指定设备编号(adb devices输出结果)
# com.bluephone', 'com.bluecart.activity.SplashActivity
driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
driver.implicitly_wait(10)
time.sleep(6)


# #点击首次使用
# el1 = driver.find_element_by_id("com.bluephone:id/systemSet1")
# el1.click()
#
# #输入展厅医院
# el2 = driver.find_element_by_id("com.bluephone:id/other_et")
# el2.send_keys('展厅医院')
#
# #选择展厅医院
# el4 = driver.find_element_by_xpath("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.support.v7.widget.RecyclerView/android.widget.LinearLayout[4]/android.widget.TextView")
# el4.click()
#
# #返回按钮
# el5 = driver.find_element_by_id("com.bluephone:id/iv_back")
# el5.click()
#
# #用户使用
# el6 = driver.find_element_by_id("com.bluephone:id/systemSet3")
# el6.click()
#
# #基础数据同步
# el7 = driver.find_element_by_id("com.bluephone:id/data1")
# el7.click()
#
# #返回按钮
# el8 = driver.find_element_by_id("com.bluephone:id/iv_back")
# el8.click()
#
#
# # el1 = driver.find_element_by_xpath("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.View/android.widget.LinearLayout[2]/android.widget.FrameLayout/android.support.v7.widget.RecyclerView/android.widget.LinearLayout[1]")
# # el1.click()
# #
# #
# # el2 = driver.find_element_by_id("com.bluephone:id/iv_back")
# # el2.click()
#
# #点击系统设置
# el1 = driver.find_element_by_id("com.bluephone:id/systemSet4")
# el1.click()
#
# #输入错误密码
# el2 = driver.find_element_by_id("android:id/input")
# el2.send_keys("330623")
#
#
# #点击确定
# el3 = driver.find_element_by_id("com.bluephone:id/md_buttonDefaultPositive")
# el3.click()

#点击系统设置
el1 = driver.find_element_by_id("com.bluephone:id/systemSet4")
el1.click()

#输入密码
el2 = driver.find_element_by_id("android:id/input")
el2.send_keys("330624")

#点击确定
el3 = driver.find_element_by_id("com.bluephone:id/md_buttonDefaultPositive")
el3.click()


el1 = driver.find_element_by_id("com.bluephone:id/systemSet4").click()
# driver.find_element_by_android_uiautomator('new UiSelector().text("设备状态")')

time.sleep(2)
if driver.find_element_by_android_uiautomator('new UiSelector().text("设备状态")'):
#
# if driver.find_element_by_tag_name('设备信息'):
    print('success')
else:
    print('fail')




# # 点击记一笔
# driver.find_element_by_xpath("//android.widget.LinearLayout[@resource-id='com.mobivans.onestrokecharge:id/main_write1']/android.widget.ImageView[1]").click()
# time.sleep(1)
#
# # 点击果蔬
# driver.find_element_by_xpath("//android.support.v7.widget.RecyclerView[@resource-id='com.mobivans.onestrokecharge:id/add_rv_cateGrid']/android.widget.LinearLayout[6]").click()
# time.sleep(1)
#
# # 备注内容
# driver.find_element_by_xpath("//android.widget.EditText[@resource-id='com.mobivans.onestrokecharge:id/add_et_remark']").send_keys('苹果','香蕉')
# time.sleep(1)
#
# # 输入价格
# driver.find_element_by_xpath("//android.widget.Button[@resource-id='com.mobivans.onestrokecharge:id/keyb_btn_5']").click()
# driver.find_element_by_xpath("//android.widget.Button[@resource-id='com.mobivans.onestrokecharge:id/keyb_btn_6']").click()
# driver.find_element_by_xpath("//android.widget.Button[@resource-id='com.mobivans.onestrokecharge:id/keyb_btn_finish']").click()
# time.sleep(1)
#
# # 断言
# passage = driver.find_element_by_xpath("//android.widget.TextView[@resource-id='com.mobivans.onestrokecharge:id/account_item_txt_remark']").text
# price = driver.find_element_by_xpath("//android.widget.TextView[@resource-id='com.mobivans.onestrokecharge:id/account_item_txt_money']").text
# print(passage)
# print(price)
# if passage == '苹果香蕉' and  price == '-56':
#     print("断言成功")
# else:
#     print("断言失败")
#
# #删除
# # TouchAction(driver).long_pree(detail[0]).perform()
# # driver.find_element_by_id("alert_tv_ok").click()


# 结束
driver.quit()